package com.gluck.cases.core.block.impl;

import com.gluck.cases.common.utils.enums.BizSerErrorEnum;
import com.gluck.cases.common.utils.utils.AssertUtil;
import com.gluck.cases.common.utils.dal.dao.AdminRoleMapper;
import com.gluck.cases.core.block.AdminRoleBlock;
import com.gluck.cases.core.modal.assemble.AdminRoleAssemble;
import com.gluck.cases.core.modal.dto.AdminRoleDTO;
import com.gluck.cases.core.modal.entity.AdminRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @ClassName AdminRoleBlockImpl
 * @Desc AdminRoleBlockImpl 实现类
 * @Author I am Gluck
 * @Date 2022/5/21 - 10:24 下午
 **/
@Service
public class AdminRoleBlockImpl implements AdminRoleBlock {

    @Autowired
    private AdminRoleMapper adminRoleMapper;

    @Override
    public boolean associateRole(AdminRoleDTO dto) {
        AdminRole adminRole = AdminRoleAssemble.AdminRoleDTOConvertAdminRole(dto);
        int insert = adminRoleMapper.insert(adminRole);
        return insert > 0;
    }

    @Override
    public boolean removeAssociate(AdminRoleDTO dto) {
        int delete = adminRoleMapper.deleteByPrimaryKey(dto.getId());
        return delete > 0;
    }

    @Override
    public boolean checkAdminRoleExists(Integer id) {
        AdminRole result = adminRoleMapper.selectByPrimaryKey(id);
        return Objects.isNull(result);
    }

    @Override
    public boolean update(AdminRoleDTO dto) {
        AdminRole adminRole = AdminRoleAssemble.AdminRoleDTOConvertAdminRole(dto);
        int update = adminRoleMapper.updateByPrimaryKey(adminRole);
        return update > 0;
    }
}
